package com.jianz.campus_markets.controller;

import com.jianz.campus_markets.domain.entity.R;
import com.jianz.campus_markets.domain.entity.SensitiveWord;
import com.jianz.campus_markets.domain.query.PageParam;
import com.jianz.campus_markets.service.SensitiveWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * {@code @Author}: lzy.
 * {@code @Date}: Created in 2023/5/17
 * {@code @Project}: information-sharing
 * {@code @Description}: 描述
 */
//@Tag(name = "敏感词管理")
@RestController
@RequestMapping("/sensitiveWord")
public class SensitiveWordController {
    @Autowired
    SensitiveWordService sensitiveWordService;

//    @PreAuthorize("@pms.hasPermission('sys:sensitiveWord:add')")
//    @Operation(summary = "添加敏感词", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/add")
    R addSensitiveWord(@RequestBody SensitiveWord sensitiveWord) {
        return sensitiveWordService.addSensitiveWord(sensitiveWord);
    }

    //    1,2,3,4
//    @PreAuthorize("@pms.hasPermission('sys:sensitiveWord:del')")
//    @Operation(summary = "删除敏感词", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/delete/{id}")
    R deleteSensitiveWord(@PathVariable("id") List<Long> id) {
        return sensitiveWordService.deleteSensitiveWord(id);
    }

//    @PreAuthorize("@pms.hasPermission('sys:sensitiveWord:update')")
//    @Operation(summary = "修改敏感词", security = {@SecurityRequirement(name = "Authorization")})
    @PutMapping("/update")
    R updateSensitiveWord(@RequestBody SensitiveWord sensitiveWord) {

        return sensitiveWordService.updateSensitiveWord(sensitiveWord);
    }

//    @Operation(summary = "获取敏感词列表", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/get")
    R getSensitiveWord(PageParam param) {
        return sensitiveWordService.getSensitiveWord(param);
    }
//    判断是否有敏感词
    @GetMapping
    R isSensitive(String text){
        return sensitiveWordService.isSensitive(text);
    }
}
